﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QLBH.DataModel;
using QLBH.Model.Controller;

namespace QLBH.CongNo
{
    public class FindArg
    {
        public DateTime Fromdate { set; get; }
        public DateTime ToDate { set; get; }
        public Guid UserID { set; get; }
        public Guid LydoID { set; get; }
    }
    public partial class FindPhieuThuChiDlg : Form
    {
        private FindArg findArgs;

        public FindArg FindArgs
        {
            get { return findArgs; }            
        }
        public FindPhieuThuChiDlg()
        {
            InitializeComponent();

            findArgs = new FindArg();
        }

        private void FindPhieuThuChiDlg_Load(object sender, EventArgs e)
        {
            findArgs.Fromdate = DateTime.Now;
            findArgs.ToDate = DateTime.Now;

            //Load DS User
            List<NHANVIEN> nhanviens = NhanVienController.GetInstance().GetAll().ToList();
            cmbNguoiTao.DataSource = nhanviens;
            cmbNguoiTao.DisplayMember = "TENNV";
            cmbNguoiTao.ValueMember = "NVID";
            cmbNguoiTao.SelectedIndex = -1;
            //Load DS Ly Do

            List<LYDO> lydos = LyDoController.GetInstance().GetAll().ToList();
            cmbLyDo.DataSource = lydos;
            cmbLyDo.DisplayMember = "TEN";
            cmbLyDo.ValueMember = "ID";            
            cmbLyDo.SelectedIndex = -1;
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            findArgs.Fromdate = dtpFromdate.Value;
            findArgs.ToDate = dtpToDate.Value;
            if (cmbNguoiTao.SelectedItem!=null)
            {
                findArgs.UserID = (cmbNguoiTao.SelectedItem as NHANVIEN).NVID;
            }           
            if (cmbLyDo.SelectedItem!=null)
            {
                findArgs.LydoID = (cmbLyDo.SelectedItem as LYDO).ID;
            }            
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void FindPhieuThuChiDlg_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode==Keys.Escape)
            {
                this.DialogResult = DialogResult.Cancel;
                this.Close();
            }
            else if (e.KeyCode==Keys.Enter)
            {
                btnSearch_Click(btnSearch, null);
            }
        }
    }
}
